package com.wontube.smr.cron;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wontube.client.extension.utils.NumberUtils;
import com.wontube.core.cron.IJobs;
import com.wontube.smr.dao.bo.ViewHistoryDao;

/**
 * @author tanggf(2012-6-1)
 *
 */
public class CleanupViewHistoryJobs implements IJobs {
	private final static Logger logger = LoggerFactory.getLogger(CleanupViewHistoryJobs.class);

	@Override
	public String name() {
		return "cleanup-view-history";
	}

	@Override
	public IJobs execute(String[] args) {
		//默认过期天数
		int day = 60;
		for (int i = 0; i < args.length; i++) {
			String arg = args[i];
			if(arg.equals("-day") && (i + 1) < args.length){
				day = NumberUtils.parseInt(args[i + 1]);
			}
		}
		
		int aff = ViewHistoryDao.cleanupViewHistories(day);
		logger.info("{} view history are deleted in {} day expires", aff, day);
		
		return this;
	}
}
